﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WhatIf
{
    public partial class ColumnConfigForm : Form{
     //   public delegate void RefreshColumnsDelegate(List<string> col);

     //   public event RefreshColumnsDelegate RefreshColumnEvent = null;

        private static List<string> _checkedColumns = new List<string>();
     //   private List<string> _hideColumns = new List<string>();

        public ColumnConfigForm(List<string> checkedColumns)
        {
            InitializeComponent();
            InitCheckedColumns(checkedColumns);
            ShowCheckedColumns();
        }

        private void ShowCheckedColumns()
        {
            if (_checkedColumns.Contains(lblAsk.Text))
            {
                lblAsk.Checked = true;
            }
            if (_checkedColumns.Contains(lblReason.Text))
            {
                lblReason.Checked = true;
            }
            if (_checkedColumns.Contains(lblConsequence.Text))
            {
                lblConsequence.Checked = true;
            }
            if (_checkedColumns.Contains(lblSafeguards.Text))
            {
                lblSafeguards.Checked = true;
            }
            if (_checkedColumns.Contains(lbls.Text))
            {
                lbls.Checked = true;
            }
            if (_checkedColumns.Contains(lbll.Text))
            {
                lbll.Checked = true;
            }
            if (_checkedColumns.Contains(lblrr.Text))
            {
                lblrr.Checked = true;
            }
            if (_checkedColumns.Contains(lblRecType.Text))
            {
                lblRecType.Checked = true;
            }
            if (_checkedColumns.Contains(lblRecNum.Text))
            {
                lblRecNum.Checked = true;
            }
            if (_checkedColumns.Contains(lblAdvice.Text))
            {
                lblAdvice.Checked = true;
            }
            if (_checkedColumns.Contains(lblPerson.Text))
            {
                lblPerson.Checked = true;
            }
            if (_checkedColumns.Contains(lblNotes.Text))
            {
                lblNotes.Checked = true;
            }
        }



        private void InitCheckedColumns(List<string> checkedColumns)
        {
            _checkedColumns.Clear();
            foreach (string s in checkedColumns){
                _checkedColumns.Add(s);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {   
            _checkedColumns.Clear();
            foreach (Control ctr in this.Controls){
                if (ctr is CheckBox && ((CheckBox)ctr).Checked)
                { 
                        _checkedColumns.Add(ctr.Text);
                }
            }
//            OnColumnsCHanged();
            Program.Workspace.HideColumns(_checkedColumns);
            this.Close();
        }

        private void lbls1_CheckedChanged(object sender, EventArgs e)
        {
            if (!lbls.Checked){
                lbll.Checked = false;
                lblrr.Checked = false;
            }
            else{
                lbll.Checked = true;
                lblrr.Checked = true;
            }
        }

        private void lbll1_CheckedChanged(object sender, EventArgs e)
        {
            if (!lbll.Checked)
            {
                lbls.Checked = false;
                lblrr.Checked = false;
            }
            else
            {
                lbls.Checked = true;
                lblrr.Checked = true;
            }
        }

        private void lblrr1_CheckedChanged(object sender, EventArgs e)
        {
            if (!lblrr.Checked)
            {
                lbll.Checked = false;
                lbls.Checked = false;
            }
            else
            {
                lbll.Checked = true;
                lbls.Checked = true;
            }
        }
    }
}
